<?php
namespace app\common\component;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Sts\Sts as StsSts;

class AliyunSts {

    public static function getStsData(){
        $config = config('aliyun_oss');
        AlibabaCloud::accessKeyClient($config['id'], $config['key'])->regionId($config['regionid'])->asDefaultClient();
        try{
            $result = StsSts::v20150401()->assumeRole()
                    ->withRoleSessionName('client_name')
                    ->withRoleArn('acs:ram::1820118166103632:role/ossmanage')
                    ->connectTimeout(60)
                    ->timeout(65)
                    ->request();
            $result = $result->toArray();
            return success($result['Credentials']);
        }catch(\AlibabaCloud\Client\Exception\ServerException $e){
            return error($e->getErrorMessage());
        }
    }
}